package com.yanjiali.controller;

import com.yanjiali.entity.ThirdParty;
import com.yanjiali.model.R;
import com.yanjiali.service.ThirdPartyService;
import com.yanjiali.webmagic.GetDataSource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package: com.yanjiali.controller
 * @Author: yanjiali
 * @Created: 2025/3/14 11:22
 */
@Api(tags = "获取第三方数据")
@RestController
@RequestMapping("/v1/thirdParty")
public class GetDataSourceController {

    @Autowired
    private GetDataSource getDataSource;

    @Autowired
    private ThirdPartyService thirdPartyService;

    @GetMapping("/getThirdPartyData")
    @ApiOperation("通过查询条件获取对应的爬虫数据")
    public R obtainThirdPartyDataByQuery(@RequestParam("query") String query) {
        getDataSource.getData(query);
        return R.ok();
    }

    //TODO 预留接口为了后续切换爬取不同站，由于不同站的html数据有所出入可能导致使用不同策略，后续可以尝试策略模式
    @PostMapping("/updateCrawlingAddress")
    @ApiOperation("预留接口暂时不用")
    public R updateCrawlingAddress() {
        return R.ok();
    }

    @GetMapping("/getOne")
    @ApiOperation("通过第三方数据id获取第三方数据对象")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对应第三方数据id")
    })
    public R<ThirdParty> getOne(@RequestParam String id) {
        ThirdParty thirdParty = thirdPartyService.getById(id);
        return R.ok(thirdParty);
    }
}
